package com.hopoke.minio.controller;

import com.hopoke.common.domain.Result;
import com.hopoke.minio.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Api(tags="文件管理")
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileController {

    private final FileService fileService;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public Result<Map<String, String>> upload(@RequestHeader String token, MultipartFile file) {
        String url = fileService.upload(file);
        HashMap<String, String> map = new HashMap<>();
        map.put("url", url);
        return Result.ok(map);
    }
}
